package com.zyf.chapter01.oo;

import java.util.ArrayList;
import java.util.List;

/**
 * 理论三 面向过程编程风格的user，数据结构和方法的定义是分开的
 * @author yifeng
 */
public class ProcessOrientedUser {
    public String name;
    public int age;
    public String gender;

}

/**
 * 一组方法集合
 */
class ProcessOrientedUserFileFormatter {
    public static ProcessOrientedUser parseToUser(String userFile) {
        // 将文本 (" 小王\t28\t 男") 解析成类user（C语言中称为结构体）
        return new ProcessOrientedUser();
    }

    public static String formatToText(ProcessOrientedUser user) {
        // 将类user（C语言中称为结构体）格式化成文本 (" 小王\t28\t 男")
        return "";
    }

    public static void sortUserByAge(ProcessOrientedUser[] users) {
        // 安装年龄从小到大排序 users
    }

    public static void formatUserFile(String userFile, String formattedUserFile) {
        // open files...
        ProcessOrientedUser[] users = new ProcessOrientedUser[1024]; // 假设最大1024个用户
        int count = 0;
        int size = 0;
        while (size++ >= 0) { // read until file is empty
            // read form file into userText...
            String userText = "";
            ProcessOrientedUser processOrientedUser = parseToUser(userText);
            users[count++] = processOrientedUser;
        }
        sortUserByAge(users);

        for (int i = 0; i < count; i++) {
            String formattedUserText =formatToText(users[i]);
            // write to new file...
        }
        // close files...
    }

    public static void main(String[] args) {
        formatUserFile("/home/kta/users.txt", "/home/kta/formatted_user.txt");
    }
}
